package com.example.demo.utils;

import com.example.demo.mapper.BookMapper;
import com.example.demo.pojo.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SelectDate {

    @Autowired
    BookMapper bookMapper;
    public int selectdate(String  arriveDate,String leaveDate,int typeID){
        int i = 0;
        int count=0;
        Map<String, Object> map = new HashMap<String, Object>();
        if (i == 0) {
            map.put("arriveDate", arriveDate);
            map.put("leaveDate", leaveDate);
            map.put("typeID", typeID);
            List<Book> books = bookMapper.findByDate(map);
            if (books.size() == 0) {
                i = 1;
            } else {
                count=count+books.size();
                i=1;
            }
        }
        if (i == 1) {
            map.put("arriveDate", arriveDate);
            map.put("leaveDate", leaveDate);
            map.put("typeID", typeID);
            List<Book> books = bookMapper.findByDate1(map);
            if (books.size() == 0) {
                i = 2;
            } else {
                count=count+books.size();
                i=2;
            }
        }
        if (i == 2) {
            map.put("arriveDate", arriveDate);
            map.put("leaveDate", leaveDate);
            map.put("typeID", typeID);
            List<Book> books = bookMapper.findByDate2(map);
            if (books.size() == 0) {
                i = 3;
            } else {
                count=count+books.size();
                i=3;
            }
        }
        if (i == 3) {
            map.put("arriveDate", arriveDate);
            map.put("leaveDate", leaveDate);
            map.put("typeID", typeID);
            List<Book> books = bookMapper.findByDate3(map);
            if (books.size() == 0) {
                if(count==0){
                    System.out.println("此时间段无人入住");
                }else {
                }

            } else {
                count=count+books.size();
            }
        }
        return count;
    }
}
